home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr26 / netprog.zip / NETPROG.TAR / lib.s5 / ttymode.c < prev    next >
C/C++ Source or Header  |  1989-12-17  |  971b  |  43 lines

  1. /*
  2.  * Copy the existing mode of a terminal to another terminal.
  3.  * Typically this is used to initialize a slave pseudo-terminal
  4.  * to the state of the terminal associated with standard input.
  5.  *
  6.  * We provide two functions to do this in 2 separate steps.
  7.  */
  8.  
  9. #include    <termio.h>
  10.  
  11.     /* See the termio(7) man page for all the details */
  12. static struct termio    tty_termio;    /* System V's structure */
  13.  
  14. /*
  15.  * Get a copy of the tty modes for a given file descriptor.
  16.  * The copy is then used later by tty_setmode() below.
  17.  */
  18.  
  19. int
  20. tty_getmode(oldfd)
  21. int    oldfd;        /* typically an actual terminal device */
  22. {
  23.     if (ioctl(oldfd, TCGETA, (char *) &tty_termio) < 0)
  24.         return(-1);
  25.  
  26.     return(0);
  27. }
  28.  
  29. /*
  30.  * Set the tty modes for a given file descriptor.
  31.  * We set the modes from the values saved by tty_getmode() above.
  32.  */
  33.  
  34. int
  35. tty_setmode(newfd)
  36. int    newfd;        /* typically a pseudo-terminal slave device */
  37. {
  38.     if (ioctl(newfd, TCSETA, (char *) &tty_termio) < 0)
  39.         return(-1);
  40.  
  41.     return(0);
  42. }
  43.